#include <unistd.h>	// include dup2()
#include <stdio.h>	// include printf()/fprintf()/fopen()
#include <stdlib.h>	// include exit()
#include <errno.h>	// include errno
#include <string.h>	// include strerror()

void error(char *msg)
{
	fprintf(stderr, "%s: %s\n",msg,strerror(errno));
	exit(1);
}

int main()
{
	int filedes;
	FILE *fp = fopen("msg.txt", "w");
	if(!fp){
		error("Can't open msg.txt !\n");
	}
	filedes = fileno(fp);
	dup2(filedes, 1);
	
	printf("hello world !\n");
		
	return 0;
}
